package my.yuan.fkzapp.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import my.yuan.fkzapp.response.CommonResult;
import my.yuan.fkzcommon.mapstruct.MenuStructMapper;
import my.yuan.fkzcommon.vo.MenuTreeVO;
import my.yuan.fkzcommon.vo.MenuVO;
import my.yuan.fkzservice.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author qy
 * @description zz
 * @date 2021-11-03
 */
@Slf4j
@RestController
@RequestMapping("/menu")
@Api(tags = {"菜单接口"})
public class MenuController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private MenuStructMapper menuStructMapper;

    @GetMapping("/tree")
    public CommonResult<MenuTreeVO> tree() {
        return CommonResult.success(menuService.tree());
    }

    @GetMapping("/list")
    public CommonResult<List<MenuVO>> list() {
        List<MenuVO> res = menuService.list().stream()
                .map(menuStructMapper::do2vo)
                .collect(Collectors.toList());
        return CommonResult.success(res);
    }
}
